package com.zy.dp.state.example4;

import java.util.Scanner;

public class ProjectManagerState implements LeaveRequestState
{

	@Override
	public void doWork(StateMachine ctx)
	{
		LeaveRequestModel lrm = (LeaveRequestModel) ctx.getBusinessVO();

		System.out.println("项目经理审核中，请稍候......");

		// 模拟用户处理界面，通过控制台来读取数据
		System.out.println(lrm.getUser() + "申请从" + lrm.getBeginDate() + "开始请假"
				+ lrm.getLeaveDays() + "天,请项目经理审核(1为同意，2为不同意)：");
		// 读取从控制台输入的数据
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		if (scanner.hasNext())
		{
			int a = scanner.nextInt();

			String result = "不同意";
			if (a == 1)
			{
				result = "同意";
			}
			lrm.setResult("项目经理审核结果：" + result);

			if (a == 1)
			{
				if (lrm.getLeaveDays() > 3)
				{

					ctx.setState(new DepManagerState());

					ctx.doWork();
				}
				else
				{

					ctx.setState(new AuditOverState());

					ctx.doWork();
				}
			}
			else
			{

				ctx.setState(new AuditOverState());

				ctx.doWork();
			}
		}
	}

}
